package com.sogou.adm.bizdev.dataimport.job;

import java.util.LinkedHashMap;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.DefaultActionProxyFactory;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
import com.opensymphony.xwork2.inject.Container;
import com.sogou.adm.bizdev.dataimport.constants.JobDataMapKey;
import com.sogou.adm.bizdev.dataimport.xwork2.XmlStringConfigurationProvider;

public class DataImportJob extends QuartzJobBean {

	@Override
	protected void executeInternal(JobExecutionContext context)
			throws JobExecutionException {
		ConfigurationManager confManager = new ConfigurationManager();
		confManager.addContainerProvider(new XWorkConfigurationProvider());
		confManager.addContainerProvider(new XmlStringConfigurationProvider(
				context.getJobDetail().getJobDataMap().getString(
						JobDataMapKey.JOB_XML_CONFIG),
				true));

		Configuration conf = confManager.getConfiguration();
		// ActionProxyFactory actionProxyFactory =
		// conf.getContainer().getInstance(ActionProxyFactory.class);
		Container containter = conf.getContainer();
		DefaultActionProxyFactory actionProxyFactory = new DefaultActionProxyFactory();
		actionProxyFactory.setContainer(containter);
		ActionProxy actionProxy = actionProxyFactory.createActionProxy(
				"/helloWorld", "helloWorld", "execute", new LinkedHashMap());

		try {
			actionProxy.execute();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
